package com.example.test.demos.web.function;

import com.example.test.demos.web.entity.Apple;
import com.example.test.demos.web.entity.Lemon;
import com.example.test.demos.web.entity.Strawberry;

import java.math.BigDecimal;

/**
 * @author Administrator
 */
public class Function {

    public static void main(String[] args) {
        functionFour(10,20,10,BigDecimal.valueOf(0.8));
    }


    /**
     * 第一题
     *
     * @param appleWeight
     * @param strawWeight
     * @return
     */
    public static void functionOne(int appleWeight, int strawWeight) {
        Apple apple = new Apple();
        apple.setPriceAndWeight(BigDecimal.valueOf(8), appleWeight);
        Strawberry strawberry = new Strawberry();
        strawberry.setPriceAndWeight(BigDecimal.valueOf(13), strawWeight);
        BigDecimal total = apple.getAmount().add(strawberry.getAmount());
        System.out.println(appleWeight + "斤苹果和" + strawWeight + "斤草莓的总价是：" + total + "元");
    }

    /**
     * 第二题
     *
     * @param appleWeight
     * @param strawWeight
     * @param lemonWeight
     * @return
     */
    public static void functionTwo(int appleWeight, int strawWeight, int lemonWeight) {
        Apple apple = new Apple();
        apple.setPriceAndWeight(BigDecimal.valueOf(8), appleWeight);

        Strawberry strawberry = new Strawberry();
        strawberry.setPriceAndWeight(BigDecimal.valueOf(13), strawWeight);

        Lemon lemon = new Lemon();
        lemon.setPriceAndWeight(BigDecimal.valueOf(20), lemonWeight);

        BigDecimal total = apple.getAmount().add(strawberry.getAmount().add(lemon.getAmount()));
        System.out.println(appleWeight + "斤苹果和" + strawWeight + "斤草莓和" + lemonWeight + "斤芒果的总价是：" + total + "元");

    }

    /**
     * 第三题
     *
     * @param appleWeight
     * @param strawWeight
     * @param lemonWeight
     * @param strawPercent
     * @return
     */
    public static void functionThree(int appleWeight, int strawWeight, int lemonWeight, BigDecimal strawPercent) {
        Apple apple = new Apple();
        apple.setPriceAndWeight(BigDecimal.valueOf(8), appleWeight);

        Strawberry strawberry = new Strawberry();
        strawberry.setPercentPriceAndWeight(BigDecimal.valueOf(13), strawWeight, strawPercent);

        Lemon lemon = new Lemon();
        lemon.setPriceAndWeight(BigDecimal.valueOf(20), lemonWeight);

        BigDecimal total = apple.getAmount().add(strawberry.getAmount().add(lemon.getAmount()));
        System.out.println(appleWeight + "斤苹果和" + strawWeight + "斤草莓和" + lemonWeight + "斤芒果的总价是：" + total + "元");
    }

    /**
     * 第四题
     *
     * @param appleWeight
     * @param strawWeight
     * @param lemonWeight
     * @param strawPercent
     * @return
     */
    private static void functionFour(int appleWeight, int strawWeight, int lemonWeight, BigDecimal strawPercent) {
        Apple apple = new Apple();
        apple.setPriceAndWeight(BigDecimal.valueOf(8), appleWeight);

        Strawberry strawberry = new Strawberry();
        strawberry.setPercentPriceAndWeight(BigDecimal.valueOf(13), strawWeight, strawPercent);

        Lemon lemon = new Lemon();
        lemon.setPriceAndWeight(BigDecimal.valueOf(20), lemonWeight);

        BigDecimal total = apple.getAmount().add(strawberry.getAmount().add(lemon.getAmount()));
        int percentOver = (int) (total.doubleValue() / 100);
        BigDecimal percentAmount = BigDecimal.valueOf(10 * percentOver);
        total = total.subtract(percentAmount);
        System.out.println(appleWeight + "斤苹果和" + strawWeight + "斤草莓和" + lemonWeight + "斤芒果的总价是：" + total + "元");
    }
}
